﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WpfELearningAuthoringTool
{
    class FileUtil
    {
        public static void Copy(string sourceDir, string targetDir)
        {
            foreach (var file in Directory.GetFiles(sourceDir))
            {
                if (!File.Exists(Path.Combine(targetDir, Path.GetFileName(file))))
                {
                    File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)));
                }
            }

            foreach (var directory in Directory.GetDirectories(sourceDir))
            {
                if (!Directory.Exists(Path.Combine(targetDir, Path.GetFileName(directory))))
                {
                     Copy(directory, Path.Combine(targetDir, Path.GetFileName(directory)));
                }
            }
        }

        public static void DirectoryDeleteAll(string directoryPath)
        {
            var rootInfo = new DirectoryInfo(directoryPath) { Attributes = FileAttributes.Normal };
            foreach (var fileInfo in rootInfo.GetFileSystemInfos()) fileInfo.Attributes = FileAttributes.Normal;
            foreach (var subDirectory in Directory.GetDirectories(directoryPath, "*", SearchOption.AllDirectories))
            {
                var subInfo = new DirectoryInfo(subDirectory) { Attributes = FileAttributes.Normal };
                foreach (var fileInfo in subInfo.GetFileSystemInfos()) fileInfo.Attributes = FileAttributes.Normal;
            }
            Directory.Delete(directoryPath, true);
        }
    }
}
